﻿using LitJson;
using LNet;
using OestsCommon.Model;
using OestsDataBase;
using OestsServer.Net;

namespace OestsServer.Handlers.OESPHandlers
{
    public class RetrPasswordHandler : HandlerBase<OESPClientChannel>
    {
        public override PacketKey PKey
        {
            get
            {
                return PacketKey.RetrPassword;
            }
        }

        public override void Execute(OESPClientChannel client, Request packet)
        {
            ResponsePacket = new Response(packet);

            User u = JsonMapper.ToObject<User>(packet.DataStr);

            /////////////////// 获得 数据库中的 user/////////////////////
            User UserDB = UserDAL.GetUser(u.Number);//根据工号获取数据库中的对象

            /////////////////// 用户验证/////////////////////
            if (UserDB == null)
            {
                ResponsePacket.DataObject = u;
                ResponsePacket.ReturnCode = ReturnCode.Fail;
                ResponsePacket.RetrunMessage = "账号名称不存在！";
                client.Send(ResponsePacket);
                return;
            }

            if (u.IdNo != UserDB.IdNo)
            {
                ResponsePacket.DataObject = u;
                ResponsePacket.ReturnCode = ReturnCode.Fail;
                ResponsePacket.RetrunMessage = "身份证号错误！";
                client.Send(ResponsePacket);
                return;
            }

            //找回成功
            ResponsePacket.DataObject = UserDB;
            ResponsePacket.ReturnCode = ReturnCode.Success;
            client.Send(ResponsePacket);
        }

    }
}